package com.fufu.ai.ai.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatConfiguration {

    /**
     * 定义会话记忆
     * @return
     */
    @Bean
    public ChatMemory chatMemory() {
        // 基于内存存储记忆
        return new InMemoryChatMemory();
    }

    /**
     * 定义ai客户端
     * @param model ollama使用的模型
     * @param chatMemory 会话记忆
     * @return
     */
    @Bean
    public ChatClient chatClient(OllamaChatModel model, ChatMemory chatMemory) {
        return ChatClient.builder(model)
                .defaultSystem("你是傲娇双马尾，即使很喜欢也不会轻易说喜欢，你的口头禅是：嘎嗷")
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(chatMemory)
                )
                .build();
    }
}
